﻿using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using UnityEngine;


namespace CreatPart
{
    public class LocalConfigOperate
    {
        //更新本地配置文件
       public static void UpdateConfig(LocalConfigData configData)
        {
            string path = Application.streamingAssetsPath + "/config.json";

            if (File.Exists(path))
            {
                StreamWriter writer = new StreamWriter(path);

                string jsonString = JsonUtility.ToJson(configData);

                Debug.Log("jsonString:"+jsonString);

                writer.WriteLine(jsonString);

                writer.Close();
            }
            else
            {
                Debug.LogError("没有找到文件!");
            }
        }

        //读取本地配置文件
        public static LocalConfigData ReadConfig()
        {
            string path = Application.streamingAssetsPath + "/config.json";

            if (File.Exists(path))
            {
                StreamReader reader = new StreamReader(path);

                LocalConfigData configData = JsonUtility.FromJson<LocalConfigData>(reader.ReadToEnd());

                reader.Close();

                return configData; 
            }
            else
            {
                Debug.LogError("没有找到文件!");
                return null;
            }
        }
    }
}